import { Platform, NativeModules, NativeEventEmitter } from 'react-native';

const { AMapLocation } = NativeModules;

const eventEmitter = new NativeEventEmitter(AMapLocation)

export default {
  async initLocation(key) {
    return AMapLocation.initLocation(Platform.select(key))
  },
  async startForegroundLocation() {
    return AMapLocation.startForegroundLocation()
  },
  //stopForegroundLocation: () => AMapLocation.stopForegroundLocation(),
  startBackgroundLocation: () => AMapLocation.startBackgroundLocation(),
  stopBackgroundLocation: () => AMapLocation.stopBackgroundLocation(),
  getLastLocation: () => AMapLocation.getLastLocation(),
  isBackgroundLocation: () => AMapLocation.isBackgroundLocation(),
  addLocationListener: listener =>
    eventEmitter.addListener("AMapGeolocation", listener),
}